package com.javaclimb.filmbuy.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.javaclimb.filmbuy.common.Result;
import com.javaclimb.filmbuy.dao.SeatInfoDao;
import com.javaclimb.filmbuy.dao.SeatInfoDao;
import com.javaclimb.filmbuy.entity.SeatInfo;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.List;

/*
* 座位service层
* */
@Service
public class SeatInfoService {

    @Resource
    private SeatInfoDao seatInfoDao;

    /*
     * 增加一个座位
     * */
    public SeatInfo add(SeatInfo seatInfo) {
        seatInfoDao.insertSelective(seatInfo);
        return seatInfo;
    }

    /*
     * 根据主键id删除一个座位
     * */
    public void delete(Long id) {
        seatInfoDao.deleteByPrimaryKey(id);
    }

    /*
     * 更新一个座位
     * */
    public void update(SeatInfo seatInfo) {
        seatInfoDao.updateByPrimaryKeySelective(seatInfo);
    }

    /*
     * 根据主键id查询一个座位
     * */
    public SeatInfo findById(Long id) {
        return seatInfoDao.selectByPrimaryKey(id);
    }
 /**
 *根据电影id查询有哪些座位已售
 */
    public SeatInfo findDetail(Long goodsId){
        return seatInfoDao.findDetail(goodsId);
    }

    /**
     * 增加或更新一个座位信息
     */
    public void save(SeatInfo seatInfo){
        if(seatInfo.getId() == null){
            seatInfoDao.insertSelective(seatInfo);
        }else{
            seatInfoDao.updateByPrimaryKeySelective(seatInfo);
        }
    }
}












